package com.manthano.security.context;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

/**
 * @author LXMRX
 */
public class UserSessionContext
{
	private Map<String, UserSession>	userSessions	= new HashMap<String, UserSession>();

	/**
	 * @param session
	 *            add UserSession
	 */
	public void registerSession(HttpSession session)
	{
		String sessionID = session.getId();
		UserSession userSession = userSessions.get(sessionID);
		if (userSession == null)
		{
			userSession = new UserSession(session);
			userSessions.put(sessionID, userSession);
		}
	}

	/**
	 * @param session
	 *            remove UserSession
	 */
	public void removeSession(HttpSession session)
	{
		userSessions.remove(session.getId());
	}

	/**
	 * @return int TotalSessionCount
	 */
	public int getTotalSessionCount()
	{
		return userSessions.size();
	}
}
